package com.itheima.threaddemo10;

public class MyThread extends Thread{
    private static int ticketCount = 100;
    private static Object obj = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                if (ticketCount <= 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "在卖票，还剩下 " + --ticketCount + " 张票");
                }
            }
        }
    }
}
